package zc.com.dao.impl;

import zc.com.dao.locationsDao;
import zc.com.entity.locations;
import zc.com.util.mavenUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class locationsDaoImpl extends mavenUtil implements locationsDao {
    Connection Conn = null;
    PreparedStatement ps=null;
    ResultSet rs=null;
    public List<locations> selectLocations() {
        Conn = getConn();
        String sql = "select * from locations";

        List<locations> list = new ArrayList<>();
        try {
            ps = Conn.prepareStatement(sql);
            rs = ps.executeQuery();

            while (rs.next()){
                Integer locationId = rs.getInt("location_id");
                String streetAddress = rs.getString("street_address");
                String postalCode = rs.getString("postal_code");
                String city = rs.getString("city");
                String stateProvince = rs.getString("state_province");
                String countryId = rs.getString("country_id");
                locations locations = new locations(locationId,streetAddress,postalCode,city,stateProvince,countryId);
                list.add(locations);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}























